<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>-->
    <!--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>-->
    <!--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->
    <!--[endif]-->
    <script type="text/javascript" src="../../common/js/public.js"></script>
    <script type="text/javascript" src="../../common/js/publicUtils.js"></script>

</head>
<body>
<div class="layui-fluid" id="flowDiv">
    <div class="zTreeBackground right" style="padding-left:1%;width:98%">
        <div class="layui-form-item" style="width:99%;margin-bottom:-10px;text-align:right;">
            <div class="layui-inline">
                <label class="layui-form-label">角色名称</label>
                <div class="layui-input-block">
                    <input type="text" id="name1" lay-verify="required|phone" autocomplete="off" class="layui-input" placeholder="请输入角色名称"/>
                    <i class="layui-icon layui-icon-search" style="position: absolute;top:8px;right: 8px;" onclick="easysearch()"></i>
                </div>
            </div>
            <button type="button" style="margin-left:12px;margin-top: -12px;" class="layui-btn layui-btn-normal" onclick="moresearch()"><i class="layui-icon layui-icon-search"></i>高级搜索</button>
        </div>
        <div class="search_float_div" style="position:absolute;z-index:999;width:99%;background-color: #f1f1f1;padding-top: 20px;text-align:left;display:none">
            <div class="layui-form-item">
                <div class="layui-inline" style="width:400px;">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline" style="width:400px;">
                    <label class="layui-form-label">组织类型</label>
                    <div class="layui-input-inline">
                        <input type="text" id="orgType" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" style="float: left;margin-left: 12px" class="layui-btn layui-btn-normal" onclick="searchTable()"><i class="layui-icon layui-icon-search"></i>查询</button>
                    <button type="button" style="float: left;margin-left: 12px" class="layui-btn layui-btn-normal" onclick="resetSearchTable()"><i class="layui-icon layui-icon-search"></i>重置</button>
                    <button type="button" class="layui-btn layui-btn-primary" onclick="canclesearch()">取消</button>
                </div>
            </div>
        </div>
        <table class="layui-hide" id="datatable" lay-filter="datatable"></table>
        <script type="text/html" id="toolbar"></script>

    </div>

</div>
</body>
<SCRIPT type="text/javascript">
    var zTreeObj,jobid,form,tableObj,table,level=0,treeNodeId=-1,selecNode,count=1,hideflag=true;
    $(function(){
        loadbutton("toolbar");//加载按钮loadbutton(id)，id为button容器id，不传默认为buttongroup
        loadTable();
    })
    /* *
     * @Author bxf
     * @Description 高级搜索
     * @Date 17:34 2019/8/30
     * @param null
     * @return
     */
    function moresearch(){
        $(".search_float_div").slideToggle();
    }
    /* *
     * @Author bxf
     * @Description 简单查询
     * @Date 17:46 2019/8/30
     * @param null
     * @return
     */
    function easysearch(){
        var name = $("#name1").val();
        var orgType = '';
        loadTable(name,orgType);
    }
    /* *
     * @Author bxf
     * @Description 取消查询
     * @Date 17:44 2019/8/30
     * @param null
     * @return
     */
    function canclesearch(){
        $(".search_float_div").slideToggle();//关闭搜素div
    }
    /* *
     * @Author bxf
     * @Description 重置查询
     * @Date 10:42 2019/10/29
     * @param null
     * @return 
     */
    function resetSearchTable(){
        $("#orgType").val("");
        $("#name").val("");
        searchTable();
    }
    /* *
     * @Author bxf
     * @Description 搜索table数据
     * @Date 17:51 2019/8/30
     * @param null
     * @return
     */
    function searchTable(){
        var name = $("#name").val();
        var orgType = $("#orgType").val();
        loadTable(name,orgType);
        $(".search_float_div").slideToggle();//关闭搜素div
    }
    /* *
     * @Author bxf
     * @Description 初始化table
     * @Date 17:51 2019/8/30
     * @param null
     * @return
     */
    function loadTable(name,orgType){

        var tableurl = publicUrl+'orgrole/selectListByOrgRole';
        layui.use(['form','table','element'], function(){
            var element = layui.element;
            form = layui.form;
            table = layui.table;
            tableObj = table.render({
                elem: '#datatable',
                size: 'sm',
                toolbar: '#toolbar',
                even: true, //开启隔行背景
                height: 'full-100',
                method: 'post',
                headers: {"Authorization":getData("Authorization")},
                url: tableurl, //stationId='+window.parent.window.parentId,//8AE7DECA-8E41-4FAB-8B30-9FD1B0B7FA33,78A9E5D8-20FB-4436-BBE8-A25EAC38D056
                where:{
                    "name":name,
                    "orgType":orgType,
                    'orgTypeName':'OrgType'
                },
                response: {
                    statusCode: 2000,
                },
                parseData: function(res){ //res 即为原始返回的数据
                    return formatTableParseData(res);
                },
                request: {
                    pageName: 'pageIndex' //页码的参数名称，默认：page
                    ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
                },
                cols: [[
                    {
                        type:'checkbox',
                        width: 60,
                    },
                    {
                        type: 'numbers',
                        title: '序号',
                        width: 80,
                        align: 'center',
                    },{
                        field: 'name',
                        title: '名称',
                        sort: true,
                        width: "14%",
                        align: 'center',
                    }, {
                        field: 'sort',
                        title: '排序',
                        sort: true,
                        width: 80,
                        align: 'center'
                    },{
                        field: 'orgTypeName',
                        title: '组织类型',
                        sort: true,
                        width: "10%",
                        align: 'center'
                    },{
                        field: 'description',
                        title: '描述',
                        width: "16%",
                        align: 'center',
                    },{
                        field: 'personList',
                        title: '用户列表',
                        sort: true,
                        width: "34%",
                        align: 'center',
                        templet:function(r){
                            var personarray = new Array();
                            $.each(r.personList,function(i,e){
                                personarray.push(e.name);
                            })
                            return personarray.join(",");
                        }
                    },{
                        field: 'id',
                        title: '岗位职责',
                        width: "8%",
                        align: 'center',
                        templet:function(r){
                            return "<p onclick=showdetail('"+r.id+"')>查看</p>";
                        }
                    }]],
                page: true
            });
            element.render();
        });
    }
    function uploadorgrole(){

        var iframeWin ;
        layer.open({
            type: 2,
            area: ["500px" , "350px"],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "角色导入",
            content: "./uploadrole.html",
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: false,
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
            }
        });
    }
    /**
     * @Author bxf
     * @Description 添加工艺工法
     * @Date 9:51 2019/7/18
     * @Param
     * @return
     **/
    function addorgrole(){
        var iframeWin ;
        layer.open({
            type: 2,
            area: ["650px" , "450px"],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "新增角色",
            content: "./addorgrole.html",
            btn: ['应用','确定', '关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: function(index, layero) {
                var resultdata = iframeWin.contentWindow.submit();//应用
                if(resultdata && resultdata.code==2000){
                    loadTable();
                }
                return false;
                //layer.closeAll();
            },
            btn2: function(index, layero){
                //按钮【按钮二】的回调
                var resultdata = iframeWin.contentWindow.submit();//保存
                if(resultdata && resultdata.code==2000){
                    loadTable();
                    layer.closeAll();
                }else{
                    return false;
                }
            },
            btn3: function(index, layero){

                },
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.voluate(1,null);//添加按钮
            }
        });
    }

    /**
     * @Author bxf
     * @Description 修改工艺工法页面
     * @Date 9:51 2019/7/18
     * @Param
     * @return
     **/
    function editorgrole(){
        var obj = table.checkStatus('datatable');
        if(!obj || obj.data.length!=1){
            layer.alert("请选择一项信息进行修改！");
            return false;
        }
        var data = obj.data[0]; //idTest 即为基础参数 id 对应的值
        var iframeWin ;
        layer.open({
            type: 2,
            area: ["650px" , "450px"],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "编辑角色",
            content: "./addorgrole.html",
            btn: ['确定', '关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: function(index, layero) {
                var resultdata = iframeWin.contentWindow.updateInfdict();
                if(resultdata && resultdata.code==2000){
                    loadTable();
                    layer.closeAll();
                }else {
                    return false;
                }
            },
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.voluate(2,data);//添加按钮
            }
        });
    }
    //关联人员
    function bindorgrole(){
        var obj = table.checkStatus('datatable');
        if(!obj || obj.data.length!=1){
            layer.alert("请选择一项信息进行人员挂接！");
            return false;
        }
        var data = obj.data[0]; //idTest 即为基础参数 id 对应的值
        var iframeWin ;
        layer.open({
            type: 2,
            area: ["1100px" , "600px"],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "分配人员",
            content: "./bindperson.html",
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: false,
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.inint(data);//添加按钮
            }
        });
    }
    //删除关联人员
    function unbindorgrole(){
        var obj = table.checkStatus('datatable');
        if(!obj || obj.data.length!=1){
            layer.alert("请选择一项信息！");
            return false;
        }
        var data = obj.data[0]; //idTest 即为基础参数 id 对应的值
        var iframeWin ;
        layer.open({
            type: 2,
            area: ["1100px" , "600px"],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "移除人员",
            content: "./unbindperson.html",
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: false,
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.inint(data);//添加按钮
            }
        });
    }
    /* *
     * @Author bxf
     * @Description 查看岗位详情
     * @Date 11:14 2019/9/2
     * @param null
     * @return
     */
    function showdetail(id){
        var layindex = layer.open({
            type: 2,
            area: ["800px" , "600px"],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "查看岗位",
            content: "./showdetailjob.html",
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: false,
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.inintData(id);//添加按钮
            }
        });
    }

    //关联岗位
    function bindjob(){
        var obj = table.checkStatus('datatable');
        if(!obj || obj.data.length!=1){
            layer.alert("请选择一项信息进行岗位挂接！");
            return false;
        }
        var data = obj.data[0]; //idTest 即为基础参数 id 对应的值
        var iframeWin ;
        var layindex = layer.open({
            type: 2,
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "关联岗位",
            content: "./bindjob.html",
            btn: ['确定','关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: function(index, layero){
                iframeWin.contentWindow.bindjobs();
            },
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.inintData(data);//添加按钮
            }
        });
        layer.full(layindex);
    }

    /* *
     * @Author bxf
     * @Description 删除记录
     * @Date 11:19 2019/7/23
     * @param null
     * @return 
     */
    function  deleteorgrole() {
        //获取选中项
        var obj = table.checkStatus('datatable');
        if(!obj || obj.data.length<1){
            layer.alert("请至少选择一项信息！");
            return false;
        }
        var ids = new Array();
        for(var i=0;i<obj.data.length;i++){
            ids.push(obj.data[i].id);
        }
        layui.use(['layer'],function(){
            var layer = layui.layer;
            layer.confirm('确定删除？', {
                btn: ['确定', '取消'] //可以无限个按钮
            }, function(){
                var delurl = 'orgrole/deleteOrgRoleByIds';
                var data = {"ids":ids.join(",")};//删除
                publicAjax (null,delurl,data,null,null,function (r) {
                    if(r.code==2000){
                        laysuccess("删除成功",null);
                        loadTable();
                    }else{
                        layerror("删除失败",null);
                    }
                });
            }, function(){
                layer.closeAll();

            });
        })
    }

    /**
     * 打开选中指定节点
     * @param treeobj
     * @param id
     */
    function getAppointNode(treeobj,id){
        if(id){
            var node = treeobj.getNodeByParam("id",id);
            treeobj.selectNode(node,true);//指定选中ID的节点
            //treeobj.expandNode(node, true, false);//指定选中ID节点展开
        }
    }

    /**
     * 刷新指定节点
     */
    function refreshSelectNode(obj,id) {
        var node = obj.getNodeByParam("id",id);
        obj.reAsyncChildNodes(node,"refresh");
    }
    /**
     * 选中某个节点
     */
    function pointNode(obj,id){
        var nodeClick = obj.getNodeByParam("id", id);
        obj.selectNode(nodeClick);//选择点
        obj.setting.callback.onClick(null, id, nodeClick);//调用点击事件
    }


</script>
</html>